package org.hawk.gwt.ppc.parser.impl;

import java.util.List;

import org.hawk.gwt.ppc.parser.AnnotationDescriptor;
import org.hawk.gwt.ppc.parser.Descriptor;
import org.hawk.gwt.ppc.parser.DescriptorVisitor;
import org.hawk.gwt.ppc.parser.ExpressionDescriptor;
import org.hawk.gwt.ppc.parser.FieldDescriptor;
import org.hawk.gwt.ppc.parser.Token;
import org.hawk.gwt.ppc.utils.PreprocessorException;

/**
 * Implementation for {@link FieldDescriptor}.
 * 
 * @author alex.bereznevatiy@gmail.com
 *
 */
final class FieldDescriptorImpl extends AbstractExpressionDescriptor implements
		FieldDescriptor {

	private String name;
	private String type;
	private List<String> modifiersList;
	private List<AnnotationDescriptor> annotations;
	private ExpressionDescriptor initializer;
	
	FieldDescriptorImpl(Token first, Token last,
			String name, String type, List<AnnotationDescriptor> annotations,
			List<String> modifiersList, ExpressionDescriptor initializer) {
		super(first, last);
		
		this.name = name;
		this.type = type;
		this.modifiersList = unmodify(modifiersList);
		this.annotations = unmodify(annotations);
		this.initializer = initializer;
	}

	/*
	 * (non-Javadoc)
	 * @see org.hawk.gwt.ppc.parser.VariableDescriptor#getName()
	 */
	public String getName() {
		return name;
	}

	/*
	 * (non-Javadoc)
	 * @see org.hawk.gwt.ppc.parser.VariableDescriptor#getType()
	 */
	public String getType() {
		return type;
	}

	/*
	 * (non-Javadoc)
	 * @see org.hawk.gwt.ppc.parser.ModificatedDescriptor#getModifiers()
	 */
	public List<String> getModifiers() {
		return modifiersList;
	}

	/*
	 * (non-Javadoc)
	 * @see org.hawk.gwt.ppc.parser.FieldDescriptor#getInitializer()
	 */
	public ExpressionDescriptor getInitializer() {
		return initializer;
	}

	/*
	 * (non-Javadoc)
	 * @see org.hawk.gwt.ppc.parser.AnnotatedDescriptor#getAnnotations()
	 */
	public List<AnnotationDescriptor> getAnnotations() {
		return annotations;
	}

	/*
	 * (non-Javadoc)
	 * @see org.hawk.gwt.ppc.parser.Descriptor#visit(org.hawk.gwt.ppc.parser.DescriptorVisitor)
	 */
	public void visit(DescriptorVisitor visitor) throws PreprocessorException {
		visitor.visit(this);
		for (Descriptor annotation : annotations) {
			if (annotation != null) {
				annotation.visit(visitor);
			}
		}
		
		if (initializer != null) initializer.visit(visitor);
	}
}
